package com.goomba.delay;

import com.goomba.demo.contants.Commons;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;


/**
 * 发送延迟，消费者必须过了延迟时间才能收到具体的数据
 */
public class Producer {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("delay_group");
        producer.setNamesrvAddr(Commons.nameSrvAddr);
        producer.setSendMsgTimeout(1500);
        producer.start();


        for (int i = 0; i < 10; i++) {
            Message message = new Message("delay_topic", "tag1" , ("delay_time" + i).getBytes(StandardCharsets.UTF_8));

            message.setDelayTimeLevel(3);
            producer.send(message);
        }


        producer.shutdown();


    }

}
